package com.ygqh.baby.service.impl;
import java.util.Date;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgSupplierSchedule;
import  com.ygqh.baby.mapper.YgSupplierScheduleMapper;
import  com.ygqh.baby.service.YgSupplierScheduleService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgSupplierScheduleExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgSupplierScheduleServiceImpl implements YgSupplierScheduleService{
	
	@Autowired
	private YgSupplierScheduleMapper ygSupplierScheduleMapper;
	
	@Override
	public List<YgSupplierSchedule> find() {
		YgSupplierScheduleExample example = new YgSupplierScheduleExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygSupplierScheduleMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgSupplierScheduleExample example = new YgSupplierScheduleExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygSupplierScheduleMapper.countByExample(example);
	}

	@Override
	public YgSupplierSchedule findById(Long id) {
		return ygSupplierScheduleMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgSupplierSchedule ygSupplierSchedule) {
		return ygSupplierScheduleMapper.insertSelective(ygSupplierSchedule);
	}

	@Override
	public int update(YgSupplierSchedule ygSupplierSchedule) {
		return ygSupplierScheduleMapper.updateByPrimaryKeySelective(ygSupplierSchedule);
	}

	@Override
	public ResultSet<YgSupplierSchedule> search(QueryInfo queryInfo,Long supplierId) {
		List<YgSupplierSchedule>  list =  ygSupplierScheduleMapper.selectSuper(queryInfo, supplierId);
		int count = ygSupplierScheduleMapper.countSuper(supplierId);
		ResultSet<YgSupplierSchedule> resultSet = new ResultSet<YgSupplierSchedule>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgSupplierScheduleExample example = new YgSupplierScheduleExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgSupplierSchedule record = new YgSupplierSchedule();
		record.setStatus(DataStatus.Delete);

		return ygSupplierScheduleMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgSupplierSchedule ygSupplierSchedule) {
		int r = 0;
		if(ygSupplierSchedule.getId() != null) {
			r = this.update(ygSupplierSchedule);
		}else {
			r = this.save(ygSupplierSchedule);
		}
		return r;
	}

	@Override
	public List<YgSupplierSchedule> selectSupplierSchedule(QueryInfo queryInfo ,Long supplierId) {
		List<YgSupplierSchedule>  list =  ygSupplierScheduleMapper.selectSuper(queryInfo, supplierId);
		return list;
	}

}

